package com.kfgj.hkp.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Created by liwensihan on 2018/5/23.
 * <p>
 * 此类主要用于生成实体的code，唯一编码问题
 */
public class CodeGenUtils {

    private static SimpleDateFormat sdf = new SimpleDateFormat("YYMMdd");

    public static String generate() {
        return generate("");
    }

    public static String generate(String prefix) {
        if (prefix == null) {
            prefix = "";
        }

        StringBuffer sb = new StringBuffer();
        sb.append(prefix);
        sb.append(sdf.format(new Date()));
        sb.append(UUID.randomUUID().toString().replaceAll("-", "").substring(0, 14 - prefix.length()));

        return sb.toString();
    }

}
